<?php
require_once __DIR__ . "/../../util/common.php";
class push_job
{
    public function perform()
    {
        $data = $this->args['data'];
        $main = $data['main'];
        $site = $data['site'];
        $api = $data['api'];
        $urls = $data['urls'];
        $result = $this->tuisong($api,$urls);
        $log = $site.'---'.$result.'---'.$urls[0];
        $date = date('y-m-d');
        $path = 'log';
        makedir($path);
        $path .= '/'.$date;
        makedir($path);
        file_put_contents("$path/$main.log",$log."<br>\n",FILE_APPEND);
    }

    private function tuisong($api,$urls){
        if(!is_array($urls)) $urls = array($urls);
        $ch = curl_init();
        $options =  array(
            CURLOPT_URL => $api,
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS => implode("\n", $urls),
            CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
        );
        curl_setopt_array($ch, $options);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

}
